package com.example.orchid.coordinatorlayoutdemo.client;

import com.example.orchid.coordinatorlayoutdemo.entity.NewsListEntity;

import retrofit.RestAdapter;
import retrofit.http.GET;
import retrofit.http.Path;
import rx.Observable;

/**
 * Created by Orchid on 2015-10-28.
 */
public class ApiManger {
    private static final String ENDPOINT = "http://news-at.zhihu.com";

    private interface ApiMangerService {
        /**
         * 获取当天的新闻
         *
         * @return
         */
        @GET("/api/4/news/latest")
        Observable<NewsListEntity> getNewsList();

        /**
         * 获取过往新闻
         *
         * @param date
         * @return
         */
        @GET("/api/4/news/before/{date}")
        Observable<NewsListEntity> getLastNewsList(@Path("date") String date);
    }


    private static final RestAdapter restAdapter = new RestAdapter.Builder()
            .setEndpoint(ENDPOINT).setLogLevel(RestAdapter.LogLevel.FULL)
            .build();
    private static final ApiMangerService apiManger = restAdapter.create(ApiMangerService.class);

    public static Observable<NewsListEntity> getNewsList() {
        return apiManger.getNewsList();
    }


    public static Observable<NewsListEntity> getLastNewsList(String date) {
        return apiManger.getLastNewsList(date);
    }
}
